import java.io.*;
/**
 * This class is called to create an ics file when Event is validated and user pressed save.  
 * @author Team Boyton(Rhys Higa, Justin Shoemaker Jeffrey Tamashiro) - ICS 314 - Final Project - 8/12/13
 */
public class ICSWriter{
	/**
	 * Single static method is called on the class with Event Object passed as a parameter
	 * @param e Event passed when inputs are validated and save button is pressed
	 */
	public static void writeMe(Event e){
		
		String fileName = e.getName();
		
		String timeZone = e.getTimeZone();
		String tzOffset = e.icsOffset();
		String dtStart = e.icsStart();
		String dtEnd = e.icsEnd();
		String dtNow = e.icsNow();
		String classification = e.getClassification();
		String comment = e.getComment();
		String resources = e.getResources();
		String location = e.getLocation();
		String recurring = e.icsRecurring() + "\n";
	
		PrintWriter fileOut = null;
		try{
			fileOut = new PrintWriter(fileName + ".ics");
		}
		catch (FileNotFoundException exception){
			System.out.println("Error");
		}

		fileOut.println("BEGIN:VCALENDAR");
		fileOut.println("PRODID:-//ICS314//Team Boyton Calendar//EN");
		fileOut.println("VERSION:2.0");
		fileOut.println("CALSCALE:GREGORIAN");
		fileOut.println("METHOD:PUBLISH");
		fileOut.println("BEGIN:VTIMEZONE");
		fileOut.println("TZID:" + timeZone);
		fileOut.println("BEGIN:STANDARD");
		fileOut.println("TZOFFSETFROM:" + tzOffset); 
		fileOut.println("TZOFFSETTO:" + tzOffset);
		fileOut.println("TZNAME:" + timeZone);
		fileOut.println("DTSTART:19700101T000000");
		fileOut.println("END:STANDARD");
		fileOut.println("END:VTIMEZONE");
		fileOut.println("BEGIN:VEVENT");
		fileOut.println("DTSTART:" + dtStart); 
		fileOut.println("DTEND:" + dtEnd);
		fileOut.print(recurring);
		fileOut.println("DTSTAMP:" + dtNow);
		fileOut.println("CLASS:" + classification);
		fileOut.println("CREATED:" + dtNow);
		fileOut.println("DESCRIPTION:");
		fileOut.println("COMMENT:" + comment);
		fileOut.println("RESOURCES:" + resources);
		fileOut.println("LAST-MODIFIED:" + dtNow);
		fileOut.println("LOCATION:" + location);
		fileOut.println("SEQUENCE:2");
		fileOut.println("STATUS:CONFIRMED");
		fileOut.println("SUMMARY:" + fileName);
		fileOut.println("TRANSP:TRANSPARENT");
		fileOut.println("END:VEVENT");
		fileOut.println("END:VCALENDAR");
		
		fileOut.close();
	}
}